package cn.opopopo.design_pattern_learn.结构型.flyweight;

import java.util.HashMap;
import java.util.Map;

class CharacterStyleFactory {
    private static final Map<String, CharacterStyle> styles = new HashMap<>();

    // 关键：通过 key 唯一标识一种样式，避免重复创建
    public static CharacterStyle getStyle(String font, int size, String color) {
        String key = font + size + color;
        return styles.computeIfAbsent(key, k -> new CharacterStyle(font, size, color));
    }

    // 查看缓存大小（用于测试）
    public static int getStyleCount() {
        return styles.size();
    }
}